﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using uzing;

namespace example_tcp_async_listener
{
    class Program_async_listener
    {
        static uzCTcpClientAsync client;
        static int dataSize = 1024;
        static byte[] buffer = new byte[dataSize];

        static void Main(string[] args)
        {
            uzCTcpListenerAsync listener = new uzCTcpListenerAsync();
            listener.Open(9000);
            listener.BeginAcceptTcpClient(endAcceptCallback);

            while (true)
            {
                System.Console.WriteLine("wating...");
                System.Threading.Thread.Sleep(1000);
            }
        }

        static void endAcceptCallback(object param)
        {
            client = param as uzCTcpClientAsync;
            client.BeginReceive(buffer, 0, dataSize, endRecvCallback, null);
        }

        static void endRecvCallback(object param)
        {
            ASCIIEncoding encoder = new ASCIIEncoding();
            System.Console.WriteLine(encoder.GetString(buffer));
            client.BeginReceive(buffer, 0, dataSize, endRecvCallback, null);
        }
    }
}
